#include <string.h>
#include <iostream>

#include "console.h"

using std::cout;
using std::endl;

void console::log(string action, bool success){

	if(!action.empty()){
		
		std::cout << endl;
		int remaining = action.length();
		int linenr = 0;

		action = trimStr(action);

		while(remaining > linelen){
			if(linenr > 0) { cout << " "; }
			cout << action.substr(linenr*linelen, linelen) << endl;
			remaining -= linelen;
			linenr++;
		}

		if(linenr > 0) { cout << " "; }
		cout << action.substr(linenr*linelen, remaining);
		cout << string(tablen-remaining, ' ');
		cout << (success ? "OK": "FAIL");
		cout << endl;
	}
}


string console::trimStr(const string& Src, const string& c)
{
	int p2 = Src.find_last_not_of(c);
	if (p2 == string::npos) return string();
	int p1 = Src.find_first_not_of(c);
	if (p1 == string::npos) p1 = 0;
	return Src.substr(p1, (p2-p1)+1);
}